package com.summer.data.table.column;

import com.summer.data.table.BaseColumn;

import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author 345480567@qq.com
 */
public class BlobColumn extends BaseColumn<byte[]> {

    public BlobColumn(String colName) {
        super(colName);
    }

    @Override
    public void fetchNotNullValue(ResultSet resultSet, Integer index) throws SQLException {
        value = getValue(resultSet, index);
    }

    public static byte[] getValue(ResultSet resultSet, Integer index) throws SQLException {
        Blob blob = resultSet.getBlob(index);
        Integer len = Math.toIntExact(blob.length());
        byte[] bytes = blob.getBytes(1, len);
        return bytes;
    }

}

